<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------

namespace app\admin\controller;

use app\common\controller\Admin;

class Till extends Admin
{
    public function index()
    {
        $template = 'till/index';
        $this->setMeta("钱柜");
        return $this->fetch($template);
    }

    /**
     * 充值列表
     * @return [html] [页面内容]
     * @author molong <ycgpp@126.com>
     */
    public function recharge()
    {
        $user = session('user_auth');
        $order = "id desc";
        $map = $this->buildMap();
        $list = db('till_recharge')->where($map)->order($order)->paginate(20);
        $data = array(
            'list' => $list,
            'page' => $list->render(),
        );
        $template = 'till/recharge';
        $this->assign($data);
        $this->setMeta("充值列表");
        return $this->fetch($template);
    }

    /**
     * 付款列表
     * @return [html] [页面内容]
     * @author molong <ycgpp@126.com>
     */
    public function payment()
    {
        $user = session('user_auth');
        $order = "id desc";
        $map = $this->buildMap();
        $list = db('till_payment')->where($map)->order($order)->paginate(20);
        $data = array(
            'list' => $list,
            'page' => $list->render(),
        );
        $template = 'till/payment';
        $this->assign($data);
        $this->setMeta("付款列表");
        return $this->fetch($template);
    }

    /**
     * 提现列表
     * @return [html] [页面内容]
     * @author molong <ycgpp@126.com>
     */
    public function deposit()
    {
        $user = session('user_auth');
        $order = "id desc";
        $map = $this->buildMap();
        $list = db('till_deposit')->where($map)->order($order)->paginate(20);
        $data = array(
            'list' => $list,
            'page' => $list->render(),
        );
        $template = 'till/deposit';
        $this->assign($data);
        $this->setMeta("提现列表");
        return $this->fetch($template);
    }

    /**
     * 结算列表
     * @return [html] [页面内容]
     * @author molong <ycgpp@126.com>
     */
    public function clearing()
    {
        $user = session('user_auth');
        $order = "id desc";
        $map = $this->buildMap();
        $list = db('till_clearing')->where($map)->order($order)->paginate(20);
        $data = array(
            'list' => $list,
            'page' => $list->render(),
        );
        $template = 'till/clearing';
        $this->assign($data);
        $this->setMeta("结算列表");
        return $this->fetch($template);
    }

    /**
     * 收款列表
     * @return [html] [页面内容]
     * @author molong <ycgpp@126.com>
     */
    public function proceeds()
    {
        $user = session('user_auth');
        $order = "id desc";
        $map = $this->buildMap();
        $list = db('till_proceeds')->where($map)->order($order)->paginate(20);
        $data = array(
            'list' => $list,
            'page' => $list->render(),
        );
        $template = 'till/proceeds';
        $this->assign($data);
        $this->setMeta("收款列表");
        return $this->fetch($template);
    }

    /**
     * 转账列表
     * @return [html] [页面内容]
     * @author molong <ycgpp@126.com>
     */
    public function transfer()
    {
        $user = session('user_auth');
        $order = "id desc";
        $map = $this->buildMap();
        $list = db('till_transfer')->where($map)->order($order)->paginate(20);
        $data = array(
            'list' => $list,
            'page' => $list->render(),
        );
        $template = 'till/transfer';
        $this->assign($data);
        $this->setMeta("转账列表");
        return $this->fetch($template);
    }

    /**
     * 退款列表
     * @return [html] [页面内容]
     * @author molong <ycgpp@126.com>
     */
    public function refund()
    {
        $user = session('user_auth');
        $order = "id desc";
        $map = $this->buildMap();
        $list = db('till_refund')->where($map)->order($order)->paginate(20);
        $data = array(
            'list' => $list,
            'page' => $list->render(),
        );
        $template = 'till/refund';
        $this->assign($data);
        $this->setMeta("退款列表");
        return $this->fetch($template);
    }

    /**
     * 创建搜索
     * @return [array] [查询条件]
     */
    protected function buildMap()
    {
        $map = array();
        $data = $this->request->param();
        foreach ($data as $key => $value) {
            if ($value) {
                if ($key == 'keyword') {
                    $map['title'] = array("LIKE", "%$value%");
                } elseif ($key == 'category') {
                    $map['category_id'] = $value;
                } elseif ($key == 'create_time') {
                    $map['create_time'] = array('BETWEEN', array(strtotime($value[0]), strtotime($value[1])));
                } else {
                    $map[$key] = $value;
                }
            }
        }
        if (isset($map['page'])) {
            unset($map['page']);
        }
        if (isset($map['model_id'])) {
            unset($map['model_id']);
        }
        $this->assign($data);
        return $map;
    }

}